<?php
/**
 * The control file of index module of ZenTaoPHP.
 *
 * The author disclaims copyright to this source code.  In place of
 * a legal notice, here is a blessing:
 * 
 *  May you do good and not evil.
 *  May you find forgiveness for yourself and forgive others.
 *  May you share freely, never taking more than you give.
 */
class process extends control
{
    /**
     * The construct function.
     * 
     * @access public
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * The index page.
     * 
     * @access public
     * @return void
     */
    public function index($recTotal=0,$recPerPage=30,$pageID=1)
    {


        $this->app->loadClass('pager', $static = true);
        $pager = new pager($recTotal, $recPerPage, $pageID);
        $model = 'monitors';

        $this->loadModel('search', 'module');
        $this->config->process->search['actionURL'] = $this->createLink('process', 'index', "status=bysearch");
        $concerned = $this->process->getuser();
        $department = $this->process->getdepartment();
        $bigcategory = $this->process->getbigtype();

       $this->config->process->search['params']['personnel']['values'] = $concerned;
        $this->config->process->search['params']['department_id']['values'] = $department;
        $this->config->process->search['params']['bigcategory']['values'] = $bigcategory;
        $fieldParams['personnel'] = $this->config->process->search['params']['personnel'];
        $fieldParams['id'] = $this->config->process->search['params']['id'];
        $fieldParams['department_id'] = $this->config->process->search['params']['department_id'];
        $fieldParams['eventtime'] = $this->config->process->search['params']['eventtime'];
        $fieldParams['bigcategory'] = $this->config->process->search['params']['bigcategory'];

        $process = $this->process->getprocess($pager);
        if($_POST){
           $process = $this->process->getseach();

        }
        $this->view->ismonitors = $this->process->ismonitors($model);
        $this->view->pager    = $pager;
        $this->view->fieldParams = $fieldParams;
        $this->view->personnel = $concerned;
        $this->view->department_id = $department;
        $this->view->bigcategory = $bigcategory;
        $this->view->module = $this->config->process->search['module'];
        $this->view->actionURL = $this->config->process->search['actionURL'];
        $this->view->title = $this->lang->process->index;
        $this->view->process = $process;

        $this->display();
    }
    public function information(){

        if($_POST){
            $ID = $this->process->create();

            if(dao::isError())  $this->send(array('result' => 'fail', 'message' => dao::getError()));
            $this->send(array('result' => 'success', 'message' => $this->lang->submitSuccess, 'locate' => $this->createLink('process', 'index')));

        }
        $model = 'monitors';
        $this->view->ismonitors = $this->process->ismonitors($model);

        $this->view->bigtype = $this->process->getbigtype();
        $this->view->unit  = $this->process->getdepartment();
        if($this->process->ismonitors($model)){
            $this->display();
        }else{
            die(js::error('权限不够') . js::locate('back'));
        }

    }

    public function delprocess(){
        $id = $this->post->id;
        $del = $this->process->delprocess($id);
        echo $del;
        exit;
    }

    public function ajaxGetDeptUsers($deptID = 0)
    {
        $users = $this->process->getusersbydept($deptID);
        $html  = '';
        foreach($users as $account => $name)
        {
            $html .= "<option value='{$account}'>$name</option>";
        }
        echo $html;
    }

    public function ajaxGetbigtype($pid){

        $types = $this->process->gettype($pid);
        $html  = '';
        foreach($types as $id => $type)
        {
            $html .= "<option value='{$id}'>$type</option>";
        }
        echo $html;
    }
    public function confirm($recTotal=0,$recPerPage=30,$pageID=1)
    {
        $this->view->user = $_SESSION['user'];
        $this->app->loadClass('pager', $static = true);
        $pager = new pager($recTotal, $recPerPage, $pageID);

        $this->loadModel('search', 'module');
        $this->config->process->search['actionURL'] = $this->createLink('process', 'confirm', "status=bysearch");
        $concerned = $this->process->getuser();
        $department = $this->process->getdepartment();
        $bigcategory = $this->process->getbigtype();

        $this->config->process->search['params']['personnel']['values'] = $concerned;
        $this->config->process->search['params']['department_id']['values'] = $department;
        $this->config->process->search['params']['bigcategory']['values'] = $bigcategory;
        $fieldParams['personnel'] = $this->config->process->search['params']['personnel'];
        $fieldParams['id'] = $this->config->process->search['params']['id'];
        $fieldParams['department_id'] = $this->config->process->search['params']['department_id'];
        $fieldParams['eventtime'] = $this->config->process->search['params']['eventtime'];
        $fieldParams['bigcategory'] = $this->config->process->search['params']['bigcategory'];
        $process = $this->process->getbydept($pager);
        if($_POST){
            $process = $this->process->getseach('confirm');

        }
        $this->view->fieldParams = $fieldParams;
        $this->view->personnel = $concerned;
        $this->view->department_id = $department;
        $this->view->bigcategory = $bigcategory;
        $this->view->module = $this->config->process->search['module'];
        $this->view->actionURL = $this->config->process->search['actionURL'];
        $this->view->pager    = $pager;
        $this->view->title = $this->lang->process->confirm;
        $this->view->process = $process;
        $this->display();
    }

    public function follow($id){
        $this->view->user = $_SESSION['user'];
        if($_POST){
            $queren = $this->process->setprocess($id);
            $this->send(array('result' => 'success', 'message' => $this->lang->confimSuccess, 'locate' => $this->createLink('process', 'confirm')));
        }

        $process = $this->process->getprocessbyid($id);
        $this->view->process =$process ;
        $this->view->users = $this->process->getusersbydept($process->department_id);
        $this->view->files = $this->process->getfile($process->m_attachment);

        $this->display();
    }

    public function concerned($recTotal=0,$recPerPage=30,$pageID=1)
    {
        $this->app->loadClass('pager', $static = true);
        $pager = new pager($recTotal, $recPerPage, $pageID);

        $this->loadModel('search', 'module');
        $this->config->process->search['actionURL'] = $this->createLink('process', 'confirm', "status=bysearch");
        $department = $this->process->getdepartment();
        $bigcategory = $this->process->getbigtype();

        $this->config->process->search['params']['department_id']['values'] = $department;
        $this->config->process->search['params']['bigcategory']['values'] = $bigcategory;
        $fieldParams['id'] = $this->config->process->search['params']['id'];
        $fieldParams['department_id'] = $this->config->process->search['params']['department_id'];
        $fieldParams['eventtime'] = $this->config->process->search['params']['eventtime'];
        $fieldParams['bigcategory'] = $this->config->process->search['params']['bigcategory'];
        $process = $this->process->getconcerned($pager);
        if($_POST){
            $process = $this->process->getseach('concerned');

        }

        $this->view->fieldParams = $fieldParams;
        $this->view->department_id = $department;
        $this->view->bigcategory = $bigcategory;
        $this->view->module = $this->config->process->search['module'];
        $this->view->actionURL = $this->config->process->search['actionURL'];
        $this->view->pager    = $pager;
        $this->view->process = $process;
        $this->view->title = $this->lang->process->concerned;
        $this->display();
    }

    public function appeal($id){
        if($_POST){
            $queren = $this->process->appeal($id);
            $this->send(array('result' => 'success', 'message' => $this->lang->submitSuccess, 'locate' => $this->createLink('process', 'concerned')));
        }
        $process = $this->process->getconbyid($id);
        $this->view->process = $this->process->getconbyid($id);
        $this->view->files = $this->process->getfile($process->m_attachment);
        $this->display();
    }
    public function particulars($id){

        $process = $this->process->getconbyid($id);
        $this->view->process = $this->process->getconbyid($id);
        $this->view->liandai = $this->process->getldbyorder($process->orders);
        $this->view->files = $this->process->getfile($process->m_attachment);
        $this->view->afiles = $this->process->getfile($process->p_attachment);

        $this->display();
    }
    public function audit($recTotal=0,$recPerPage=10,$pageID=1)
    {
        $this->app->loadClass('pager', $static = true);
        $pager = new pager($recTotal, $recPerPage, $pageID);
        $this->view->pager    = $pager;
        $model = 'audit';

        $this->loadModel('search', 'module');
        $this->config->process->search['actionURL'] = $this->createLink('process', 'confirm', "status=bysearch");
        $concerned = $this->process->getuser();
        $department = $this->process->getdepartment();
        $bigcategory = $this->process->getbigtype();

        $this->config->process->search['params']['personnel']['values'] = $concerned;
        $this->config->process->search['params']['department_id']['values'] = $department;
        $this->config->process->search['params']['bigcategory']['values'] = $bigcategory;
        $fieldParams['personnel'] = $this->config->process->search['params']['personnel'];
        $fieldParams['id'] = $this->config->process->search['params']['id'];
        $fieldParams['department_id'] = $this->config->process->search['params']['department_id'];
        $fieldParams['eventtime'] = $this->config->process->search['params']['eventtime'];
        $fieldParams['bigcategory'] = $this->config->process->search['params']['bigcategory'];
        $process = $this->process->getprocess($pager);
        if($_POST){
            $process = $this->process->getseach();

        }

        $this->view->fieldParams = $fieldParams;
        $this->view->personnel = $concerned;
        $this->view->department_id = $department;
        $this->view->bigcategory = $bigcategory;
        $this->view->module = $this->config->process->search['module'];
        $this->view->actionURL = $this->config->process->search['actionURL'];
        $this->view->ismonitors = $this->process->ismonitors($model);
        $this->view->title = $this->lang->process->audit;
        $this->view->process = $process;
        $this->view->title = $this->lang->process->audit;
        $this->display();
    }

    public function approval($id){
        $model = 'audit';
        if($_POST){
            $queren = $this->process->approval($id);
           // var_dump($queren);
            //exit;
            $this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess, 'locate' => $this->createLink('process', 'audit')));
        }
        $this->view->ismonitors = $this->process->ismonitors($model);
        $process = $this->process->getconbyid($id);
        $this->view->process = $this->process->getconbyid($id);
        $this->view->files = $this->process->getfile($process->m_attachment);
        $this->view->afiles = $this->process->getfile($process->p_attachment);
        $this->view->types = $this->process->gettypes();
        $this->view->bigtype = $this->process->getbigtype();
        $this->view->unit  = $this->process->getdepartment();
        $this->display();
    }

    public function updatescore(){

      // var_dump($this->process->updatescore());

    }



}
